package com.lagou.order.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.Orders;
import com.lagou.common.pojo.OrderGoods;
import com.lagou.order.fegin.GoodsFeign;
import com.lagou.order.mapper.OrderMapper;
import com.lagou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public Orders selectById(Integer id) {
        return orderMapper.selectById(id);
    }

    @Override
    public IPage<Orders> selectPage(Integer yeshu) {
        IPage<Orders> iPage = orderMapper.selectPage(new Page<>(yeshu,10),null);
        return iPage ;
    }



    @Autowired
    private GoodsFeign goodsFeign;

    @Override
    public List<Goods> selectGoods(Integer Id) {
        List<Goods> goodsList = new ArrayList<>();
        List<OrderGoods> orderGoods = orderMapper.orderGoodsId(Id);
        for (OrderGoods orderGood : orderGoods) {
            Goods goods = goodsFeign.queryById(orderGood.getGoodsId());
            if (goods!=null){
                goodsList.add(goods);
            }
        }
        return goodsList;
    }

}
